﻿using B.S.DataBase.MyProject.Domain.Materials;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyProject.Infrastructure.Interface;
using MediatR;
using T.E.ERP.Read.API.Applicantions.Command.MaterialsCommand.QueryMaterialsCommand;

namespace T.E.ERP.Read.API.Applicantions.CommandHandler.MaterialsCommandCommand.QueryMaterialsCommandHandler
{
    /// <summary>
    /// 选择物料
    /// </summary>
    public class Matern_CodeCommdHandler : IRequestHandler<Matern_CodeCommd, APIResult<List<Matern_Code>>>
    {

        private readonly IBaseRepository<Matern_Code> repository;

        public Matern_CodeCommdHandler(IBaseRepository<Matern_Code> repository)
        {
            this.repository = repository;
        }

        /// <summary>
        /// 处理
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<APIResult<List<Matern_Code>>> Handle(Matern_CodeCommd request, CancellationToken cancellationToken)
        {
            APIResult<List<Matern_Code>> result = new APIResult<List<Matern_Code>>();
            result.Code = APIEnum.成功;
            result.Msg = APIEnum.查询成功.ToString();

            var list = repository.GetAll().Result;

            result.data =list.ToList();
            return Task.FromResult(result);
        }
    }
}
